﻿Public Class DialogCekStok

    Private Sub DialogCekStok_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TreeGrid1.ProcName = New String() {"proc_searchallEqual", "proc_searchallEqual"}
        ComCariBy.SelectedIndex = 0
        setgrid()
    End Sub

    Private Sub setgrid()
        Dim obj() As Object
        Dim param As New List(Of Object)
        If ComCariBy.Text = "Menu" Then
            param.Clear()
            obj = New Object() {"*", "vstokmenufix", "iditemmenu", ComId.SelectedValue}
            param.Add(obj)
            obj = New Object() {"*", "vstokmenua", "iditemmenu", ComId.SelectedValue}
            param.Add(obj)

            TreeGrid1.Params = param.ToArray
            TreeGrid1.displaycolumn.Clear()
            TreeGrid1.displaycolumn.Add("iditemmenu")
            TreeGrid1.displaycolumn.Add("namaitemmenu")
            'TreeGrid1.displaycolumn.Add("namaitem")
            TreeGrid1.displaycolumn.Add("qty")
            TreeGrid1.displaycolumn.Add("stok")
            TreeGrid1.displaycolumn.Add("idproduk")
            TreeGrid1.displaycolumn.Add("namaproduk")
            TreeGrid1.displaycolumn.Add("qtydetail")


            TreeGrid1.setGridPproperty("iditemmenu")
        ElseIf ComCariBy.Text = "Produk" Then
            param.Clear()
            obj = New Object() {"*", "vstokprodukfix", "idproduk", ComId.SelectedValue}
            param.Add(obj)
            obj = New Object() {"*", "vstokproduka", "idproduk", ComId.SelectedValue}
            param.Add(obj)

            TreeGrid1.Params = param.ToArray
            TreeGrid1.displaycolumn.Clear()
            TreeGrid1.displaycolumn.Add("idproduk")
            TreeGrid1.displaycolumn.Add("namaproduk")
            'TreeGrid1.displaycolumn.Add("namaitem")
            TreeGrid1.displaycolumn.Add("qty")
            TreeGrid1.displaycolumn.Add("stok")
            TreeGrid1.displaycolumn.Add("iditem")
            TreeGrid1.displaycolumn.Add("namaitem")
            TreeGrid1.displaycolumn.Add("qtyitem")
            TreeGrid1.displaycolumn.Add("satuan")


            TreeGrid1.setGridPproperty("idproduk")
        End If
    End Sub
    Private Sub ComCariBy_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub ComCariBy_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComCariBy.SelectedIndexChanged
        If ComCariBy.Text = "Menu" Then
            Dim dt As New DataTable
            If Utils.executeSP("proc_searchall", New Object() {"*", "rsitemmenu", "namaitemmenu", ""}, dt) Then
                If Utils.RowExist(dt) Then
                    ComId.DataSource = dt
                    ComId.DisplayMember = "namaitemmenu"
                    ComId.ValueMember = "iditemmenu"
                End If
            End If
        ElseIf ComCariBy.Text = "Produk" Then
            Dim dt As New DataTable
            If Utils.executeSP("proc_searchall", New Object() {"*", "rsproduk", "namaproduk", ""}, dt) Then
                If Utils.RowExist(dt) Then
                    ComId.DataSource = dt
                    ComId.DisplayMember = "namaproduk"
                    ComId.ValueMember = "idproduk"
                End If
            End If

        End If
    End Sub

    Private Sub ComId_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComId.SelectedValueChanged
        If Not ComId.SelectedValue.ToString = "System.Data.DataRowView" Then
            setgrid()
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim DialogMenu As New DialogMenu
        DialogMenu.ShowDialog()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim DialogProduk As New DialogProduk
        DialogProduk.ShowDialog()
    End Sub
End Class